#include <cstdio>
using namespace std;

void AddOneDay(int, int, int);

int main()
{
    int num;
    while(scanf(" %d", &num) != EOF) {
        int year, month, day;
        for(int i = 0; i < num; i++) {
            scanf(" %d %d %d", &year, &month, &day);
            AddOneDay(year, month, day);
        }
    }
}

void AddOneDay(int year, int month, int day)
{
    int month_list[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    if (month == 12 && day == 31) {
        printf("%d-01-01\n", year + 1);
        return;
    }

    if (day < month_list[month - 1]) {
        printf("%d-%02d-%02d\n", year, month, day + 1);
        return;
    } else {
        printf("%d-%02d-01\n", year, month + 1);
        return;
    }

    return;
}